var t = getApp();

Page({
    data: {
        available_amount: "",
        available_amount_num: 0,
        amount: "",
        remarks: "",
        language: {}
    },
    onShow: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        }), this.initData(), this.getExpendData();
    },
    getExpendData: function() {
        var a = this, e = t.getNetAddresss("plugin.public-fund.frontend.controllers.fund.expendIndex");
        wx.showLoading({
            title: "loading"
        }), t._getNetWork({
            url: e,
            data: {},
            success: function(t) {
                if (1 === t.data.result) {
                    var e = t.data.data, i = e.amount, n = e.is_expend_member;
                    a.setData({
                        available_amount: i,
                        available_amount_num: parseFloat(i.replace(",", ""))
                    }), n || wx.navigateBack({
                        delta: 1
                    });
                } else wx.showToast({
                    title: t.data.msg
                });
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    debounceMethods: function() {
        var t = this;
        this.debounceTimer && clearTimeout(this.debounceTimer);
        var a = !this.debounceTimer;
        this.debounceTimer = setTimeout(function() {
            t.debounceTimer = null;
        }, 800), a && this.submitRequest.apply(this);
    },
    submitRequest: function() {
        var a = this;
        if (this.data.amount) if (this.data.remarks) if (this.data.amount > this.data.available_amount_num) wx.showToast({
            title: "支出金额不能大于可支出金额"
        }); else {
            var e = t.getNetAddresss("plugin.public-fund.frontend.controllers.fund.expend");
            wx.showLoading({
                title: "loading"
            }), t._getNetWork({
                url: e,
                data: {
                    amount: this.data.amount,
                    remark: this.data.remarks
                },
                success: function(t) {
                    1 === t.data.result ? (wx.showToast({
                        title: "申请成功"
                    }), a.timer = setTimeout(function() {
                        wx.redirectTo({
                            url: "../../public_welfare_fund/publicWelfare/publicWelfare"
                        });
                    }, 500)) : wx.showToast({
                        title: t.data.msg
                    });
                },
                complete: function() {
                    wx.hideLoading();
                }
            });
        } else wx.showToast({
            title: "请输入备注"
        }); else wx.showToast({
            title: "请输入支出金额"
        });
    },
    changeAmount: function(t) {
        this.setData({
            amount: t.detail
        });
    },
    changeRemarks: function(t) {
        this.setData({
            remarks: t.detail
        });
    },
    clickAll: function() {
        this.setData({
            amount: this.data.available_amount
        });
    },
    initData: function() {
        this.setData({
            available_amount: 0,
            amount: "",
            remarks: ""
        });
    },
    onShareAppMessage: function() {},
    onHide: function() {
        clearTimeout(this.timer);
    }
});